import * as  cc from 'cc'
import { MagicPoker } from '../manager/MagicManager';
import { GameManager } from '../manager/GameManager';

export default class MagicItem {

    readonly magic: MagicPoker;
    readonly node: cc.Node;

    constructor(magicPoker: MagicPoker, pokerNode: cc.Node) {
        this.magic = magicPoker;
        this.node = pokerNode;

        cc.resources.load(magicPoker.getTexture().path, cc.ImageAsset, (err, result) => {
            // 添加PokerTexture
            const spriteComp = pokerNode.getComponent(cc.Sprite);
            if (!spriteComp) return;
            const frame = spriteComp.spriteFrame
            if (!frame) return;
            const texture = cc.SpriteFrame.createWithImage(result);
            // 设置大小
            texture.rect = cc.math.rect((result.width - frame.rect.width) / 2,
                (result.height - frame.rect.height) / 2,
                frame.rect.width,
                frame.rect.height);
            spriteComp.spriteFrame = texture;
        })
    }

    changeSelect(isSelect: boolean) {
        const transform = this.node.getComponent(cc.UITransform);
        if (!transform) return;
        if (isSelect) {
            transform.anchorY = 0.2;
        } else {
            transform.anchorY = 0.5;
        }
    }

    showDialog(game: GameManager) {
        // 创建一个空白的 显示在屏幕中心

        // 添加内容
    }
}